package net.uzen.office.member;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.uzen.office.common.controller.BaseController;
import net.uzen.office.member.service.MemberService;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.servlet.ModelAndView;

public class MemberController extends BaseController {
	
	private static final Log logger = LogFactory.getLog(MemberController.class);

	private MemberService memberService;

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	
	public ModelAndView member(HttpServletRequest request,
			HttpServletResponse response) {
		logger.debug(" >> " + this.getClass().getName());
		System.out.println("Member >> ");
		return new ModelAndView("member/member");
	}

	public ModelAndView list(HttpServletRequest request,
			HttpServletResponse response) {
		Map requestMap = new HashMap();

		int pageNo = Integer.parseInt(StringUtils.isBlank(request.getParameter("pageNo")) ? "1" : request.getParameter("pageNo"));
		
		requestMap.put("pageNo", pageNo);

		Map<String, Object> resultMap = memberService.getMemberList(requestMap);

		ModelAndView resultMV = new ModelAndView("member/list");
		resultMV.addAllObjects(resultMap);

		return resultMV;
	}
	
	public ModelAndView errorTest(HttpServletRequest request,
			HttpServletResponse response) {
		String errorVar = null;
		if(errorVar.equals("1")) 
			System.out.println("=");
		return new ModelAndView();
	}
	
	public ModelAndView messagesTest(HttpServletRequest request,
			HttpServletResponse response) {
		
		Locale english = Locale.ENGLISH;
		Locale korean = Locale.KOREAN;
		
		System.out.println(english.toString());
		System.out.println(korean.toString());
		
		ApplicationContext ctx = getApplicationContext();
		
		System.out.println("==================================================");
		System.out.println(getApplicationContext().getMessage("msg", null, english));
		System.out.println(getApplicationContext().getMessage("msg", null, korean));
		System.out.println("==================================================");
		System.out.println(getMessageSourceAccessor().getMessage("msg", english));
		System.out.println(getMessageSourceAccessor().getMessage("msg", korean));
		System.out.println("==================================================");
		System.out.println(getMessage("msg", english));
		System.out.println(getMessage("msg", korean));
		System.out.println("==================================================");
		
		return new ModelAndView();
	}
}
